import fileinput, glob, string, sys, os, csv

#it counts the occorrences of species names, sums these for taxa and then prints to the screen those orthogroups that are present only in certain predefined taxa or groups of taxa

orthogroup = glob.glob("OG*edited.fa")   #change extension accordingly

for filename in orthogroup:
    fh = open(filename)
    content = fh.read()
    fh.close()
    Anoploda_count = content.count('Anoploda')
    OzestheR_count = content.count('OzestheR')
    Ozesther_count = content.count('Ozesther')
    Eulimnad_count = content.count('Eulimnad')
    Eoleptes_count = content.count('Eoleptes')
    LimnadBi_count = content.count('LimnadBi')
    LimnadPa_count = content.count('LimnadPa')
    Branchin_count = content.count('Branchin')
    Simoceph_count = content.count('Simoceph')
    Ceriodap_count = content.count('Ceriodap')
    Sida_cry_count = content.count('Sida_cry')
    Palaemon_count = content.count('Palaemon')
    Xibal116_count = content.count('116Xibal')
    Calanus__count = content.count('Calanus_')
    Temora_l_count = content.count('Temora_l')
    Polyphem_count = content.count('Polyphem')
    Anchistr_count = content.count('Anchistr')
    Xibal128_count = content.count('128Xibal')
    Typhlaty_count = content.count('Typhlaty')
    Godzilli_count = content.count('Godzilli')
    Speoneba_count = content.count('Speoneba')
    Lasionec_count = content.count('Lasionec')
    Triops_a_count = content.count('Triops_a')
    Cycle145_count = content.count('145Cycle')
    Cycle146_count = content.count('146Cycle')
    Eocyzicu_count = content.count('Eocyzicu')
    Eurycerc_count = content.count('Eurycerc')
    Podon_le_count = content.count('Podon_le')
    Evadne_c_count = content.count('Evadne_c')
    Pagurus__count = content.count('Pagurus_')
    Semibala_count = content.count('Semibala')
    Caprella_count = content.count('Caprella')
    Crangon__count = content.count('Crangon_')
    Bosmina__count = content.count('Bosmina_')
    Scaphole_count = content.count('Scaphole')
    Chthamal_count = content.count('Chthamal')
    Neogonod_count = content.count('Neogonod')
    PenaeusD_count = content.count('PenaeusD')
    Loxothyl_count = content.count('Loxothyl')
    Emerita__count = content.count('Emerita_')
    Eusarsie_count = content.count('Eusarsie')
    Hutchins_count = content.count('Hutchins')
    Idotea_b_count = content.count('Idotea_b')
    Libinia__count = content.count('Libinia_')
    Stenopus_count = content.count('Stenopus')
    Enoplome_count = content.count('Enoplome')
    Thamnoce_count = content.count('Thamnoce')
    Streptoc_count = content.count('Streptoc')
    BranchLi_count = content.count('BranchLi')
    Moina_sp_count = content.count('Moina_sp')
    Pollicip_count = content.count('Pollicip')
    Derochei_count = content.count('Derochei')
    Leptoche_count = content.count('Leptoche')
    Cylindro_count = content.count('Cylindro')
    Paranesi_count = content.count('Paranesi')
    Lightiel_count = content.count('Lightiel')
    Anaspide_count = content.count('Anaspide')
    Cumella__count = content.count('Cumella_')
    TriopsLo_count = content.count('TriopsLo')
    TriopsGr_count = content.count('TriopsGr')
    Conchoec_count = content.count('Conchoec')
    Artemia__count = content.count('Artemia_')
    Macrothr_count = content.count('Macrothr')
    Lepiduru_count = content.count('Lepiduru')
    Lynceus__count = content.count('Lynceus_')
    Cyzicus__count = content.count('Cyzicus_')
    Paralimn_count = content.count('Paralimn')
    Metalimn_count = content.count('Metalimn')
    DaphniaP_count = content.count('DaphniaP')
    Drosophi_count = content.count('Drosophi')
    Euphausi_count = content.count('Euphausi')
    Ixodes___count = content.count('Ixodes__')
    Procamba_count = content.count('Procamba')
    PenaeusV_count = content.count('PenaeusV')
    Eucyclop_count = content.count('Eucyclop')
    Echinoga_count = content.count('Echinoga')
    Lernaea__count = content.count('Lernaea_')
    Limulus__count = content.count('Limulus_')
    Leucauge_count = content.count('Leucauge')
    Cryptops_count = content.count('Cryptops')
    Crateros_count = content.count('Crateros')
    Caligus__count = content.count('Caligus_')
    Metabeta_count = content.count('Metabeta')
    Tigriopu_count = content.count('Tigriopu')
    Cherax_d_count = content.count('Cherax_d')
    Eurytemo_count = content.count('Eurytemo')
    Argulus__count = content.count('Argulus_')
    Acerento_count = content.count('Acerento')
    Anurida__count = content.count('Anurida_')
    Meinerte_count = content.count('Meinerte')
    Occasjap_count = content.count('Occasjap')
    Thermobi_count = content.count('Thermobi')
    Glomerid_count = content.count('Glomerid')
    Strigimi_count = content.count('Strigimi')

 
    Hexapoda_sum = Drosophi_count + Occasjap_count + Meinerte_count + Anurida__count + Acerento_count + Thermobi_count
    Branchiopoda_sum = Anchistr_count + Polyphem_count + Sida_cry_count + Ceriodap_count + Simoceph_count + Triops_a_count + Cycle145_count + Cycle146_count + Eocyzicu_count + Podon_le_count + Evadne_c_count + Bosmina__count + Scaphole_count + DaphniaP_count + Metalimn_count + Paralimn_count + Cyzicus__count + Lynceus__count + Lepiduru_count + Macrothr_count + Artemia__count + TriopsGr_count + TriopsLo_count + Moina_sp_count + BranchLi_count + Streptoc_count + Thamnoce_count + Ozesther_count + LimnadPa_count + Branchin_count + Eulimnad_count + OzestheR_count + Eoleptes_count + LimnadBi_count
    Cephalocarida_sum = Lightiel_count + Hutchins_count 
    Remipedia_sum = Godzilli_count + Xibal128_count + Xibal116_count + Lasionec_count
    Malacostraca_Copepoda_Cirripedia_sum = Eurytemo_count + Metabeta_count + Leptoche_count + Pollicip_count + Libinia__count + Temora_l_count + Calanus__count + Palaemon_count + Speoneba_count + Typhlaty_count + Eurycerc_count + Pagurus__count + Semibala_count + Caprella_count + Crangon__count + Chthamal_count + Neogonod_count + PenaeusD_count + Loxothyl_count + Emerita__count + Lernaea__count + Echinoga_count + Eucyclop_count + PenaeusV_count + Procamba_count + Caligus__count + Tigriopu_count + Cherax_d_count + Idotea_b_count + Anaspide_count + Cumella__count + Euphausi_count + Enoplome_count + Stenopus_count
    Ostracoda_Argulus_Mysta_sum = Paranesi_count + Derochei_count + Cylindro_count + Conchoec_count + Eusarsie_count + Argulus__count
    outgroups_sum = Ixodes___count + Strigimi_count + Cryptops_count + Leucauge_count + Glomerid_count + Anoploda_count + Limulus__count + Crateros_count

# in the following groups of taxa are created that contain each gene at least once each, and the gene should be misisng in all other groups; results are to be printed to screen
# decisive groups for single taxa relate to orthogroups probably present in the common ancestor of the group
    if Hexapoda_sum >= 1 and Branchiopoda_sum >= 1 and Remipedia_sum >= 1 and Cephalocarida_sum >= 1 and Malacostraca_Copepoda_Cirripedia_sum >=1 and Ostracoda_Argulus_Mysta_sum >=1:
        print("Decisive", filename)          
	